<template>
	<view :style="themeColor">
		<view class="page">
			<view class="flex flex-direction flex-wrap align-stretch benben-position-layout flex skill_flex_0"
				:style="{height:(88+StatusBarRpx)+'rpx',paddingTop:StatusBarRpx+'rpx', }">
				<view class='flex flex-wrap align-center justify-between skill_fd0_0'>
					<view class='flex flex-wrap align-center skill_fd0_0_c0' @tap.stop="handleJumpDiy" data-type="back"
						data-url="1">
						<text class='fu-iconfont2  skill_fd0_0_c0_c0'>&#xE794;</text>
					</view>
					<view class='flex flex-wrap align-center'>
						<text class='skill_fd0_0_c1_c0'>选择分类</text>
					</view>
					<view class='flex align-center justify-end skill_fd0_0_c0'>
						<text class='skill_fd0_0_c2_c0' @tap.stop="setSelection()"
							v-if=" appSystemIdentification!='Wechat'">确定</text>
					</view>
				</view>

			</view>
			<view :style="{height: (88+StatusBarRpx)+'rpx'}"></view>

			<ly-tree ref="tree" node-key="aid" :tree-data="treeData" :props="props" :ready="ready"
				:show-checkbox="type!=1" @node-expand="handleNodeExpand" @node-click="handleNodeClick">
			</ly-tree>
			<!---flex布局flex布局开始-->
			<!-- 	<view class="flex flex-direction flex-wrap align-stretch benben-flex-layout skill_flex_1"
				v-if=" skillList.length!=0">
				<benben-select-diy ref="showSelectPopup1692326281449"
					class-name='flex flex-direction align-stretch flex' :items.sync="skillList" v-model="skillData.id"
					:label.sync="skillData.name" default-type="aid" default-label="name" :allow-cancel='true'
					type="checkbox" :disabled='false' :max-select="-1">
					<template v-for='(item,key0) in skillList'>
						<view v-if="item.isSelected" class='flex align-center justify-between flex skill_fd1_0_c0'
							:key="key0" @tap="$refs.showSelectPopup1692326281449.tapHandle(key0)">
							<text class='flex-sub skill_fd1_0_c0_c0'>{{item.name}}</text>
							<image class='skill_fd1_0_c0_c1' mode="aspectFit" :src='STATIC_URL+"133.png"'></image>
						</view>
						<view v-else class='flex align-center justify-between flex skill_fd1_0_c0' :key="key0"
							@tap="$refs.showSelectPopup1692326281449.tapHandle(key0)">
							<text class='flex-sub skill_fd1_0_c1_c0'>{{item.name}}</text>
							<image class='skill_fd1_0_c0_c1' mode="aspectFit" :src='STATIC_URL+"81.png"'></image>
						</view>
					</template></benben-select-diy>
			</view> -->
			<!---flex布局flex布局结束-->
			<view class="flex flex-wrap align-start justify-center benben-position-layout flex skill_flex_2"
				v-if=" appSystemIdentification=='Wechat'">
				<button class='skill_fd2_0' @tap.stop="setSelection()">确定</button>
			</view>
			<view :style="{height: '120rpx'}" v-if=" appSystemIdentification=='Wechat'"></view>

		</view>
	</view>
</template>
<script>
	import LyTree from '@/components/ly-tree/ly-tree.vue'
	import {
		validate
	} from '@/common/utils/validate.js'

	export default {
		components: {
			LyTree
		},


		data() {
			return {
				// "skillList": [],
				"employeesData": [],
				// "skillData": {
				// 	"id": "",
				// 	"name": ""
				// },
				// "skillLable": "",
				"aid": "",
				type: '',
				ready: false, // 这里用于自主控制loading加载状态，避免异步正在加载数据的空档显示“暂无数据”
				treeData: [],
				props: {
					label: 'name', // 指把数据中的‘personName’当做label也就是节点名称
					children: 'children' // 指把数据中的‘childs’当做children当做子节点数据
				},
			};
		},
		computed: {
			themeColor() {
				return this.$store.getters.themeColor
			},
			/**
			 * @returns 
			 * Android       安卓
			 * IOS       苹果
			 * Web       H5 或 pc
			 * Wechat       微信小程序
			 * Alipay       支付宝小程序
			 * Baidu       百度小程序
			 * ByteBounce       抖音小程序
			 * 360       360小程序
			 * FastApp       快应用
			 */
			appSystemIdentification() {
				return this.$store.state.appSystemIdentification
			}
		},
		watch: {},
		onLoad(options) {
			let {
				aid
			} = options
			if (aid !== undefined) this.aid = aid
			this.getEmployeesFunc()
		},
		onUnload() {

		},
		onReady() {

		},
		onShow() {

		},
		onHide() {

		},
		onResize() {

		},
		onPullDownRefresh() {
			this.getEmployeesFunc()
		},
		onReachBottom(e) {

		},
		onPageScroll(e) {

		},
		methods: {
			// uni-app中emit触发的方法只能接受一个参数，所以会回传一个对象，打印对象即可见到其中的内容
			handleNodeClick(obj) {
				console.log('handleNodeClick', obj);
			},
			handleNodeExpand(obj) {
				console.log('handleNodeExpand', obj);
			},
			//确定选择
			setSelection() {
				var obj = {}
				let data = this.$refs.tree.getCheckedNodes()
				obj.aid = data.map(item => item.aid).join(',')
				obj.name = data.map(item => item.name).join(',')
				uni.$emit('skillData', obj)
				uni.navigateBack(1)
			},
			findItem(data) {
				for (const item of data) {
					if (!item.children) {
						var arr = this.aid.split(",")
						for (let i = 0; i < arr.length; i++) {
							if (item.aid == arr[i]) {
								item.checked = true
							}
						}
					} else {
						const res = this.findItem(item.children) //（一直不满足if，一直else，直到满足了if）
						if (res) { //res的值是 一直递归循环 直到到最后满足if找到的item，赋值给res。
							return res
						}
					}
				}
				return null
			},
			//获取技能列表
			async getEmployeesFunc() {
				//请求方法
				//数据验证

				let dataemployeesData = await this.$api.get(global.apiUrls.post63e4bbbda555d, {

				});

				if (dataemployeesData.data.code != 1) {
					this.$message.info(dataemployeesData.data.msg);
					return
				}
				let infoemployeesData = dataemployeesData.data;
				this.treeData = infoemployeesData.data
				this.treeData.forEach(item => item.disabled = true)
				this.findItem(this.treeData)
				this.ready = true;
			},
			//抛出事件
			throwEventFunc() {
				uni.$emit('skillData', this.skillData)
				this.$urouter.navigateBack(1);
			}
		}
	};
</script>
<style lang="scss" scoped>
	.page {
		width: 100vw;
		overflow-x: hidden;
		min-height: calc(100vh - var(--window-bottom));
		background: #fff;
		background-size: 100% auto;
	}

	.skill_flex_0 {
		border-bottom: 1px solid #eee;
		background: #fff;
		width: 750rpx;
		height: 88rpx;
		overflow: hidden;
		z-index: 10;
		top: 0rpx;
		background-size: 100% auto !important;
	}

	.skill_fd0_0_c2_c0 {
		color: #333333;
		font-size: 32rpx;
		font-weight: 500;
		line-height: 45rpx;
	}

	.skill_fd0_0_c1_c0 {
		font-size: 36rpx;
		font-weight: 500;
		color: #333333;
	}

	.skill_fd0_0_c0_c0 {
		font-size: 36rpx;
		color: #333;
		font-weight: 500;
	}

	.skill_fd0_0_c0 {
		width: 120rpx;
		height: 88rpx;
	}

	.skill_fd0_0 {
		padding: 0rpx 32rpx 0rpx 32rpx;
		height: 88rpx;
	}

	.skill_flex_1 {
		padding: 0rpx 32rpx 0rpx 32rpx;
	}

	.skill_fd1_0_c1_c0 {
		color: #333333;
		font-size: 32rpx;
		font-weight: 400;
		line-height: 45rpx;
		-webkit-line-clamp: 1;
		overflow: hidden;
		text-overflow: ellipsis;
		display: -webkit-box;
		-webkit-box-orient: vertical;
		margin: 0rpx 24rpx 0rpx 0rpx;
	}

	.skill_fd1_0_c0_c1 {
		width: 40rpx;
		height: 40rpx;
		border-radius: 0rpx 0rpx 0rpx 0rpx;
	}

	.skill_fd1_0_c0_c0 {
		color: #333333;
		font-size: 32rpx;
		font-weight: 400;
		line-height: 45rpx;
		margin: 0rpx 24rpx 0rpx 0rpx;
		-webkit-line-clamp: 1;
		overflow: hidden;
		text-overflow: ellipsis;
		display: -webkit-box;
		-webkit-box-orient: vertical;
	}

	.skill_fd1_0_c0 {
		border-bottom: 1px solid #eee;
		padding: 32rpx 0rpx 32rpx 0rpx;
	}

	//按钮样式
	.skill_flex_2 {
		width: 750rpx;
		height: 120rpx;
		overflow: hidden;
		z-index: 10;
		bottom: calc(0rpx + var(--window-bottom));
	}

	.skill_fd2_0 {
		background: #3090FF;
		border-radius: 44rpx;
		width: 686rpx;
		line-height: 88rpx;
		font-size: 32rpx;
		color: #fff;
		height: 88rpx;
	}
</style>